<template>
  <div>
    <p>count得值是:{{ count }}</p>
    <button @click="add">+1</button>
  </div>
</template>

<script>
export default {
  name: 'MyCounter',
  // 1.声明自定义事件
  emits: ['countChange'],
  data() {
    return {
      count: 0
    }
  },
  methods: {
    add() {
      this.count++
      // this.$emit()触发自定义事件
      this.$emit('countChange', this.count)
    }
  }
}
</script>

<style></style>
